<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Auth;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    protected function success(){
        return [
            'info'=>'success',
            'msg'=>__('message.success_info')
        ];
    }
    protected function fail(){
        return [
            'info'=>'fail',
            'msg'=>__('message.fail_info')
        ];
    }
    protected function del_success(){
        return [
            'info'=>'success',
            'msg'=>'删除成功'
        ];
    }
    protected function edit_success(){
        return [
            'info'=>'success',
            'msg'=>'修改成功'
        ];
    }

    protected function page_json_render($paginate){

        return [
            'msg'=>'成功',
            'code'=>0,
            'data'=>$paginate['data'],
            'total'=>$paginate['total']
        ];
    }
    protected function unPermissionMessage(){
        return [
            'info'=>'fail',
            'msg'=>'没有权限访问'
        ];
    }
    //权限
    protected function adminPermission($permission){

        if(Auth::check()){
            //取出用户所有权限
            $user=User::find(Auth::id());

            $allPermission=$user->getAllPermissions()->pluck('name')->toArray();

            if($allPermission&&in_array($permission,$allPermission)){
                return true;
            }
        }

        return abort('401','没有权限访问');

    }
    public function commonMsgWap($status,$msg,$url=''){
        return view('web.commonMsg.index',
            [
                'status'=>$status,
                'msg'   =>  $msg,
                'url'   =>  $url
            ]);
    }
}
